package cn.iocoder.yudao.module.moa.service.qjapply;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.moa.controller.admin.qjapply.vo.*;
import cn.iocoder.yudao.module.moa.dal.dataobject.qjapply.QjApplyDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.moa.dal.mysql.qjapply.QjApplyMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * MOA 请假申请 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class QjApplyServiceImpl implements QjApplyService {

    @Resource
    private QjApplyMapper qjApplyMapper;

    @Override
    public Long createQjApply(QjApplySaveReqVO createReqVO) {
        // 插入
        QjApplyDO qjApply = BeanUtils.toBean(createReqVO, QjApplyDO.class);
        qjApplyMapper.insert(qjApply);
        // 返回
        return qjApply.getId();
    }

    @Override
    public void updateQjApply(QjApplySaveReqVO updateReqVO) {
        // 校验存在
        validateQjApplyExists(updateReqVO.getId());
        // 更新
        QjApplyDO updateObj = BeanUtils.toBean(updateReqVO, QjApplyDO.class);
        qjApplyMapper.updateById(updateObj);
    }

    @Override
    public void deleteQjApply(Long id) {
        // 校验存在
        validateQjApplyExists(id);
        // 删除
        qjApplyMapper.deleteById(id);
    }

    private void validateQjApplyExists(Long id) {
        if (qjApplyMapper.selectById(id) == null) {

        }
    }

    @Override
    public QjApplyDO getQjApply(Long id) {
        return qjApplyMapper.selectById(id);
    }

    @Override
    public PageResult<QjApplyDO> getQjApplyPage(QjApplyPageReqVO pageReqVO) {
        return qjApplyMapper.selectPage(pageReqVO);
    }

}
